import loading_img from '@/assets/img/loading.png'
import menu_title from '@/assets/img/battlecity2.png'
import sound_start from '@/assets/sound/sound-start.mp3'
import sound_fire from '@/assets/sound/sound-fire2.mp3'
import sound_hit from '@/assets/sound/sound-fire.mp3'
import sound_boom1 from '@/assets/sound/sound-boom1.mp3'
import sound_boom2 from '@/assets/sound/sound-boom2.mp3'
import sound_win from '@/assets/sound/sound-win.mp3'
import sound_over from '@/assets/sound/sound-over.mp3'
import title from '@/assets/img/battlecity2.png'
import over from '@/assets/img/gameover.png'
import over_2 from '@/assets/img/gameover2.png'
import tank from '@/assets/img/player1.png'
import tank2 from '@/assets/img/player2.png'
import enemy from '@/assets/img/enemy.png'
import button_arrow from '@/assets/img/button-arrow.png'
import button_a from '@/assets/img/button-a.png'
import bonus from '@/assets/img/bonus.png'
import bore from '@/assets/img/bore.png'
import bullet from '@/assets/img/bullet.png'
import explode1 from '@/assets/img/explode1.png'
import explode2 from '@/assets/img/explode2.png'
import tile from '@/assets/img/tile.png'
import levels from '@/assets/img/levels.json'

import shield from '@/assets/img/shield.png'




export default class Loading extends Phaser.Scene {
  preload() {
    this.load.spritesheet('loading_img', loading_img, { frameWidth: 80, frameHeight: 24 })
    this.load.image('menu_title', menu_title)

    this.load.audio("sound-start", sound_start);
    this.load.audio("sound-fire", sound_fire);
    this.load.audio("sound-hit", sound_hit);
    this.load.audio("sound-boom1", sound_boom1);
    this.load.audio("sound-boom2", sound_boom2);
    this.load.audio("sound-win", sound_win);
    this.load.audio("sound-over", sound_over);

    this.load.image("title", title);
    this.load.image("over", over);
    this.load.image("over-2", over_2);

    this.load.spritesheet("tank", tank, { frameWidth: 16, frameHeight: 16 }); 
    this.load.spritesheet("tank2", tank2, { frameWidth: 16, frameHeight: 16 }); 
    this.load.spritesheet("enemy", enemy, { frameWidth: 16, frameHeight: 16 }); 
    this.load.spritesheet("button-arrow", button_arrow, { frameWidth: 32, frameHeight: 32 });  
    this.load.spritesheet("button-a", button_a, { frameWidth: 48, frameHeight: 48 });  
    
    this.load.spritesheet("bonus", bonus, { frameWidth: 16, frameHeight: 15 });  
    this.load.spritesheet("bore", bore, { frameWidth: 16, frameHeight: 16 });  
    this.load.spritesheet("bullet", bullet, { frameWidth: 6, frameHeight: 6 });  
    this.load.image("explode1", explode1);
    this.load.image("explode2", explode2);

    this.load.spritesheet("shield", shield, { frameWidth: 16, frameHeight: 16 });
    
    this.load.tilemapTiledJSON("levels", levels);
    this.load.image("tile", tile);  

    this.load.spritesheet('tile', tile, {
      frameWidth: 16,
      frameHeight: 16,
      spacing: 2,
    })

    
  }

  create() {
    let loading = this.add.sprite(this.sys.game.config.width / 2, this.sys.game.config.height / 2, 'loading_img')
    this.anims.create({
      key: 'lodding',
      frames: this.anims.generateFrameNumbers('loading_img', {
        // 左跑涉及到前4帧
        start: 0,
        end: 2
      }),
      // 每秒跑10帧
      frameRate: 5,
      // -1表示loop
      repeat: -1
    })
    loading.anims.play('lodding', true)
    setTimeout(() => {
      this.scene.start('menu')
    }, 1000)
  }
}


